<template>
  <div class="app-container">

    <el-table v-loading="loading" :data="workRateList" @selection-change="handleSelectionChange">
      <el-table-column label="评价人员id" align="center" prop="rater" />
      <el-table-column label="任务id" align="center" prop="taskId" />
      <el-table-column label="评分" align="center" prop="rate" />
      <el-table-column label="评价内容" align="center" prop="rateContent" />
      <el-table-column label="工资变化" align="center" prop="salaryChange" />
      <el-table-column label="投诉" align="center" prop="complaintReason" />
      <el-table-column label="有效性" align="center" prop="isValid" :formatter="statusFormat"/>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="cancelRate(scope.row)"
          >无效化</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改【请填写功能名称】对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">

        <el-form-item label="投诉详情" prop="complaintReason">
          <el-input v-model="form.complaintReason" placeholder="请输入" />
        </el-form-item>

      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button :loading="buttonLoading" type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listWorkRate, getWorkRate, delWorkRate, addWorkRate, updateWorkRate,complaint,complaintList,confirmComplaint } from "@/api/hotel/workRate";

export default {
  name: "WorkRate",
  data() {
    return {
      // 按钮loading
      buttonLoading: false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 【请填写功能名称】表格数据
      workRateList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        workerId: undefined,
        rater: undefined,
        rate: undefined,
        rateContent: undefined,
        rateType: undefined,
        salaryChange: undefined
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询【请填写功能名称】列表 */
    getList() {
      this.loading = true;
      complaintList(this.queryParams).then(response => {
        this.workRateList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        workRateId: undefined,
        workerId: undefined,
        rater: undefined,
        rate: undefined,
        rateContent: undefined,
        rateType: undefined,
        salaryChange: undefined
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.workRateId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },

    
    cancelRate(row) {
      confirmComplaint(row).then(response => {
              this.$modal.msgSuccess("无效成功");
              this.getList();
            });
    },
    /** 提交按钮 */
    submitForm() {
        if(this.form.isValid=="y"){
          complaint(this.form).then(response => {
              this.$modal.msgSuccess("投诉成功");
              this.open = false;
              this.getList();
            }).finally(() => {
              this.buttonLoading = false;
            });
        }
        else{
          this.$modal.confirm("不能对无效评分投诉！");
        }

    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const workRateIds = row.workRateId || this.ids;
      this.$modal.confirm('是否确认删除【请填写功能名称】编号为"' + workRateIds + '"的数据项？').then(() => {
        this.loading = true;
        return delWorkRate(workRateIds);
      }).then(() => {
        this.loading = false;
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {
      }).finally(() => {
        this.loading = false;
      });
    },
    statusFormat(row,column){
      if(row.isValid=="y"){
        return "有效";
      }
      else if(row.isValid=="n"){
        return "无效";
      }
    }
  }
};
</script>
